package com.dayaokeji.rhythmschoolstudent.client.common.exam.adapter;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.dayaokeji.rhythmschoolstudent.R;
import com.dayaokeji.rhythmschoolstudent.utils.DateUtils;
import com.dayaokeji.server_api.domain.TestResult;

/**
 * Created by Gorden on 2017/10/24.
 * 开始结果列表
 */

public class TestResultListAdapter extends BaseQuickAdapter<TestResult,BaseViewHolder> {

    public TestResultListAdapter() {
        super(R.layout.item_test_result, null);
    }

    @Override
    protected void convert(BaseViewHolder helper, TestResult item) {
        helper.setText(R.id.tv_student_name,mContext.getString(R.string.test_student_name,item.getUserName()));
        helper.setText(R.id.tv_student_score, getFormatScore(item));
        helper.setText(R.id.tv_test_title,item.getExamName());
        helper.setText(R.id.tv_test_start_time, DateUtils.format(item.getStartTime(),DateUtils.FORMAT_DATETIME_SHORT));
        helper.setText(R.id.tv_student_time_cost,String.valueOf(item.getTime()));
        helper.setText(R.id.tv_test_status,item.getStatusName());
    }

    /**
     * 成绩显示样式
     * @param item
     * @return
     */
    private String getFormatScore(TestResult item) {
        final StringBuilder scoreBuild = new StringBuilder();
        scoreBuild.append(mContext.getString(R.string.test_score));
        scoreBuild.append("<font color='#ff2d2d'>");
        scoreBuild.append(item.getScore());
        scoreBuild.append("</font>");
        scoreBuild.append("/");
        scoreBuild.append("<font color='#1C89E6'>");
        scoreBuild.append(item.getTotalScore());
        scoreBuild.append("</font>");

        return scoreBuild.toString();
    }
}
